f1 can be found directly. Write a script to obtain f2:
1 2 3 4 5 6 7 8 9 10 11
s = 'fo`guci' s = list(s) s = [ord(x) for x in s] s.reverse() for i in range(8): if i%2==1: s[i] -= 2 else: s[i] -= 1 f1 = 'GXY{do_not_' print(f1 + ''.join([chr(x) for x in s]))
The result is GXY{do_not_hate_me}.
rsa
The download contains a key and an enc file. For RSA we need to find e, d, and Euler’s totient.
The key contains a Base64-encoded public key. enc will not open and is probably an encrypted byte string. Since the public key is not very long, we can use factordb.com to factor its modulus and then compute the totient.
1 2 3 4 5 6
import base64
N = 'MDwwDQYJKoZIhvcNAQEBBQADKwAwKAIhAMAzLFxkrkcYL2wch21CM2kQVFpY9+7+/AvKr1rzQczdAgMBAAE=' N = base64.b64decode(N) N = [hex(x)[2:].zfill(2) for x in N] print('0x'+''.join(N))
Next, find the inverse of 65537 modulo phi; this is our d.
d = gmpy.invert(65537, phi)
This gives d = 0x6bdf061f1331506dde814a5a543d0b056806ae6ebc1d3a7737978f7828753e3099b58c0adbe3ce3db07bb1e7c2c1904dd7e7cdd07c2a6825cf78218ca01.
Once we have d, apply the following to the ciphertext: $$ cipher^{d} % N=plain $$ Read enc and convert it to hex:
1 2 3 4 5
c = '' with open('rsa\\41c4e672-98c5-43e5-adf4-49d75db307e4\\output\\flag.enc', 'rb') as f: c = f.read() c = [hex(x)[2:].zfill(2) for x in c] print('0x'+''.join(c))
c = 0x4196c0594a5e000a96b878b67cd724795b13a8f2ca54da06d0f19c28be689b62
Then calculate pow(c, d, N). The result is 0x10b2ee66d8c3be7d67bbeb85060700e9e4f598f627f746931aadb7a7bc17db0d573267c99c8e326e5e8458b63794ccc20493d26bfc0d147028808b91a6c0.
That is not a usable string at all!
An online RSA decryption tool does not produce anything useful either.
I looked for an online public-key analyzer and discovered that I had parsed the key incorrectly. Its Base64 data has a specific structure and cannot be interpreted directly as I had done.
Enter it at http://tool.chacuo.net/cryptrsakeyparse to get:
n = C0332C5C64AE47182F6C1C876D42336910545A58F7EEFEFC0BCAAF5AF341CCDD
Factoring gives 285960468890451637935629440372639283459 and 304008741604601924494328155975272418463.
Then calculate Euler’s totient: phi = 81176168860169991027846870170527607562179635470395365333547868786951080991441L.
The inverse is d = 0xb378155840fb2b8fbdd869db5b7e91994f1ece256ee1175ec2c2bd3a4a795ad1.
Finally, use Python’s rsa module to decrypt the file. The hardest part was not decryption but configuring gmpy2; I still have not managed it on Windows.
1 2 3 4 5 6 7 8 9 10 11 12 13
import rsa import gmpy2
n = 0xC0332C5C64AE47182F6C1C876D42336910545A58F7EEFEFC0BCAAF5AF341CCDD e = 0x10001 p = 285960468890451637935629440372639283459 q = 304008741604601924494328155975272418463 phi = 81176168860169991027846870170527607562179635470395365333547868786951080991441 d = 0xb378155840fb2b8fbdd869db5b7e91994f1ece256ee1175ec2c2bd3a4a795ad1 privKey = rsa.PrivateKey(n, e, d, p, q) with open('./flag.enc', 'rb') as f: content = f.read() print(rsa.decrypt(content, privKey))
The final flag is flag{decrypt_256}.
Should this not be a crypto challenge?
CrackRTF
This x86 executable has a Notepad icon. Open it in IDA and find the main function:
memset(&pass1, 0, 0x104u); memset(&s, 0, 0x104u); v4 = 0; printf("pls input the first passwd(1): "); scanf("%s", &pass1); if ( strlen((constchar *)&pass1) != 6 ) { printf("Must be 6 characters!\n"); ExitProcess(0); } v4 = atoi((constchar *)&pass1); if ( v4 < 100000 ) ExitProcess(0); strcat((char *)&pass1, "@DBApp"); v0 = strlen((constchar *)&pass1); j_sha1(&pass1, v0, &s); if ( !_strcmpi(&s, "6E32D0943418C2C33385BC35A1470250DD8923A9") ) { printf("continue...\n\n"); printf("pls input the first passwd(2): "); memset(&pass2, 0, 0x104u); scanf("%s", &pass2); if ( strlen(&pass2) != 6 ) { printf("Must be 6 characters!\n"); ExitProcess(0); } strcat(&pass2, (constchar *)&pass1); memset(&s, 0, 0x104u); v1 = strlen(&pass2); j_getMd5((BYTE *)&pass2, v1, &s); if ( !_strcmpi("27019e688a4e62a649fd99cadaafdb4e", &s) ) { if ( !(unsigned __int8)sub_40100F(&pass2) ) { printf("Error!!\n"); ExitProcess(0); } printf("bye ~~\n"); } } return0; }
The logic appears to salt and hash the first string, then append it to the second string on success. I could not find the hash or MD5 in a lookup, so I brute-forced it.
1 2 3 4 5 6 7 8
import hashlib salt = '@DBApp'
for i in range(100000, 1000000): data = str(i)+salt hash_sha1 = hashlib.sha1(data.encode()) if hash_sha1.hexdigest().upper() == '6E32D0943418C2C33385BC35A1470250DD8923A9': print(data)
The first value is 123321. I tried brute-forcing the second, but it is not numeric, so I looked it up directly.
That gives ~!3a@0123321@DBApp, but it is wrong?
The first two checks are not the end of it. I followed the third check:
It takes data from a section of the program, XORs it with the earlier data, and writes the flag to dbapp.rtf. Rather than trace further, I opened the file and found the flag.
Flag{N0_M0re_Free_Bugs}
pyre
The download is a compiled Python .pyc file. I used uncompyle6 to recover the source:
uncompyle6.exe a.pyc > a.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
# uncompyle6 version 3.7.2 # Python bytecode 2.7 (62211) # Decompiled from: Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] # Embedded file name: encode.py # Compiled at: 2019-08-19 21:01:57 print'Welcome to Re World!' print'Your input1 is your flag~' l = len(input1) for i in range(l): num = ((input1[i] + i) % 128 + 128) % 128 code += num
for i in range(l - 1): code[i] = code[i] ^ code[(i + 1)]
The decompiled Python 2 code will not run as written. In particular, code += num raises an error in both Python 2 and 3. I guessed the intended operation was code[i] += num.
((a+b) % p + c) % p = (a + (b+c) % p) % p can simplify the modulo operation.
num = ((input1[i] + i) % 128 + 128) % 128 = (input1[i] + i) % 128 (assuming the flag is no longer than 128 characters).
That leaves a small ASCII search space for each position. A script can try the characters and compare the results:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
import string table = [ord(x) for x in string.printable] code = ['\x1f', '\x12', '\x1d', '(', '0', '4', '\x01', '\x06', '\x14', '4', ',', '\x1b', 'U', '?', 'o', '6', '*', ':', '\x01', 'D', ';', '%', '\x13'] code = [ord(x) for x in code] for i in range(len(code)-2, -1, -1): code[i] ^= code[i+1] for i in range(len(code)): code[i] -= i if code[i] notin table or code[i] <= 10: code[i] += 128
print(code) code = [chr(x) for x in code] print(''.join(code))
GWHT{Just_Re_1s_Ha66y!}
younger driver
PEiD identifies UPX packing. Unpack it to obtain a 32-bit executable.
After renaming the variables, the main function shows a transformation followed by a comparison:
table = 'QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm' + '\0' data = 'TOiZiZtOrYaToUwPnToBsOaOapsyS'
defdecry(data): ret = [] for i in data: idx = table.find(i) if i.islower(): ret.append(chr(idx + 0x60)) else: ret.append(chr(idx + 0x26)) return''.join(ret)
defencry(data:str): ret = list(data) for i in range(len(data)): if data[i].isupper(): idx = ord(data[i]) - 0x26 else: idx = ord(data[i]) - 0x60 ret[i] = table[idx] return''.join(ret)
flag = '' for i in range(len(data)): for j in string.ascii_letters: if(encry(j) == data[i]): flag += j print(flag) e = encry(flag) print(e)
The recovered flag is dhGsGsDhCeJdHfAiXdHwKhJhJIKEk, but the submission is rejected.
Since I cannot debug it, I install msvcrt100d.dll and try again. It also has anti-debugging: it checks the process list for tools such as od and ida, but I can use x32dbg.
Without IDA alongside it, locating the code is harder. Patching the check helps.
After patching, I try debugging in IDA to see what happens.
It still does not work: there is a stack-pointer error. OllyDbg also freezes at this point, and forcing a patch produces an error.
Let’s inspect the multithreading.
There is the missing piece: a mutex. The code waits for the lock, transforms the input, decrements a value, and waits again.
table = 'QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm' + '\0' data = 'TOiZiZtOrYaToUwPnToBsOaOapsyS'
defencry(data:str): ret = list(data) for i in range(len(data)): if data[i].isupper(): idx = ord(data[i]) - 0x26 else: idx = ord(data[i]) - 0x60 ret[i] = table[idx] return''.join(ret)
flag = '' for i in range(len(data)): for j in string.ascii_letters: if(encry(j) == data[i]): flag += j
mutex = 0 for i in range(len(flag)): if mutex == 0: print(data[i], end='') mutex = 1 else: print(flag[i], end='') mutex = 0
ThisisthreadofwindowshahaIsES: the last character becomes \0, so there should be multiple solutions. None of my submissions worked. Another writeup explains that the expected final character is E: during the contest any final character worked, but this platform accepts only E.
Photo Album
The challenge warns that this is malware and should not be installed on a phone. My system also flags the download.
The APK contains an email-sending routine and configuration values that are decoded through native methods. Static inspection of the native library reveals an encoded email address. The operational code, configuration values, and address are omitted here because the sample is identified as malware.
2019 Red Hat Cup easyRE
The ELF runs under WSL, but prints nothing. I started looking for useful strings instead.
The string search leads to a candidate function. With no obvious print calls to guide me, I suspect the binary has been stripped.
off_6CC090 can be repeatedly Base64-decoded to reveal an article at https://bbs.pediy.com/thread-254172.htm about setting traps. Oh no—does that mean I have fallen for one?
I followed transf1, but its mm128 operations were hard to decipher. Stepping through it shows that this part checks the string length.
That lets me construct an input and apply the XOR to reveal:
Info:The first four chars are flag
What is this? The second input must repeatedly Base64-decode to the URL. I have a strong feeling I am being tricked.
Submitting it does not work. I am baffled; this really is a trap.
Another writeup finally exposed the trick: code is hidden in the fini section. The function below main_fake contains the real check.
I could not trace much further. The beginning is the flag and there is also a comparison involving v5. Constructing the input recovers the full flag. I could not find a way into this loop with any input, so I had to analyze it statically; I am also unsure what v5 and v7 do.
1 2 3 4 5 6 7 8 9 10 11 12 13
data = [ 0x40, 0x35, 0x20, 0x56, 0x5D, 0x18, 0x22, 0x45, 0x17, 0x2F, 0x24, 0x6E, 0x62, 0x3C, 0x27, 0x54, 0x48, 0x6C, 0x24, 0x6E, 0x72, 0x3C, 0x32, 0x45, 0x5B] key= 'flag' key = list(key) key = [ord(x) for x in key] for i in range(len(key)): key[i] ^= data[i]
for i in range(len(data)): data[i] ^= key[i % 4]
print(''.join([chr(x) for x in data]))
The flag is flag{Act1ve_Defen5e_Test}.
That trap cost me a day.
BJDCTF JustRE
In IDA, I searched the strings and followed a reference to the click handler:
The handler displays a flag after 19999 clicks. I tried submitting the displayed value directly, and it worked. After the previous puzzle, I was expecting another trap!
SUCTF2019 signin
There are only a few functions in this x86-64 ELF, but the arithmetic looks intimidating at first.
The calls look like GMP operations, and the relationship between the values looks like RSA. That suggests factoring the modulus.
Given: $$ n=0Xe4bcdf0332b194a4c28376b1a3c18bf8604a4dc3efe363e00708c402d510e9e5\ e = 0X10001\ c = 0Xad939ff59f6e70bcbfad406f2494993757eee98b91bc244184a377520d06fc35 $$ Find m, where $m=c^d % n$.
Factor directly to get p=282164587459512124844245113950593348271 and q=366669102002966856876605669837014229419.
Calculate Euler’s totient phi = (p-1)*(q-1), then obtain d with d = gmpy2.invert(65537, phi).
Calculate m = pow(c, d, n), yielding m = 0x73756374667b50776e5f405f68756e647265645f79656172737d.
Convert it to get suctf{Pwn_@_hundred_years}.
V&N2020 StrangeCPP
This 64-bit executable has a suspicious fake flag. After the last puzzle, I made sure to look beyond the obvious path.
There is also a section named 00cfg, although I could not tell what it was for. Another guessing game.
A writeup points out suspicious data pushed by main_fake at the start. Follow it.
Following that data leads to a function worth debugging. I checked its arguments:
The first attempt does not satisfy the condition. Tracing it shows a key of 8. I guessed that the last character is }, giving a key of 64 and the flag format flag{MD5(theNum)}.
I guessed the number was the key, 64, but neither the MD5 of 64 nor @ worked. Tracing the function above suggests that we must solve this equation:
We need to find the input; only v7 is involved, so test candidates directly.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
import hashlib data = [ 0x26, 0x2C, 0x21, 0x27, 0x3B, 0x0D, 0x04, 0x75, 0x68, 0x34, 0x28, 0x25, 0x0E, 0x35, 0x2D, 0x69, 0x3D] for i in range(len(data)): data[i] ^= 64 print(''.join([chr(x) for x in data])) result = 0x242EE21A
<!DOCTYPE Html /> <html> <head> <title>FLARE On 2017</title> </head> <body> <inputtype="text"name="flag"id="flag"value="Enter the flag" /> <inputtype="button"id="prompt"value="Click to check the flag" /> <scripttype="text/javascript"> document.getElementById("prompt").onclick = function () { var flag = document.getElementById("flag").value; var rotFlag = flag.replace(/[a-zA-Z]/g, function(c){returnString.fromCharCode((c <= "Z" ? 90 : 122) >= (c = c.charCodeAt(0) + 13) ? c : c - 26);}); if ("PyvragFvqrYbtvafNerRnfl@syner-ba.pbz" == rotFlag) { alert("Correct flag!"); } else { alert("Incorrect flag, rot again"); } } </script> </body> </html>
The page contains an encryption function for the login. My JavaScript is not good enough to reverse it comfortably, so I tested candidate characters instead.
jscode = """ function encry(c){return String.fromCharCode((c <= "Z" ? 90 : 122) >= (c = c.charCodeAt(0) + 13) ? c : c - 26);} """ jsc = execjs.compile(jscode)
out = "PyvragFvqrYbtvafNerRnfl@syner-ba.pbz" table = string.printable defencry(s:str): return jsc.call("encry", s)
flag = [] for i in range(len(out)): if out[i] in string.ascii_letters: for letter in table: if encry(letter) == out[i]: flag.append(letter) print(letter, end=' ') break else: flag.append('_') else: flag.append(out[i]) print(''.join(flag)) print([ord(x) for x in flag]) print(len(out)) print(len(flag))
The flag is ClientSideLoginsAreEasy@flare-on.com. The S had been replaced with 9; guessing the correction produced the result.
V&N 2020 CSRe
This is a .NET executable, but dnSpy initially shows a lot of unreadable text. I ran it through de4dot and returned to the checks.
// Token: 0x0600000F RID: 15 RVA: 0x00002374 File Offset: 0x00000574 privatestaticvoidMain(string[] args) { if (!Class1.smethod_1()) { return; } bool flag = true; Class3 @class = new Class3(); string str = Console.ReadLine(); if (Class3.smethod_0("3" + str + "9") != "B498BFA2498E21325D1178417BEA459EB2CD28F8") { flag = false; } string text = Console.ReadLine(); string string_ = Class3.smethod_0("re" + text); string text2 = @class.method_0(string_, "63143B6F8007B98C53CA2149822777B3566F9241"); for (int i = 0; i < text2.Length; i++) { if (text2[i] != '0') { flag = false; } } if (flag) { Console.WriteLine("flag{" + str + text + "}"); } } }
The first input is wrapped in 3 and 9 before its SHA-1 is compared. Looking up B498BFA2498E21325D1178417BEA459EB2CD28F8 gives 314159, so the input itself is 1415.
Next look up the SHA-1 after XOR. The condition text2[i] != '0' confused me, so I looked up the original value and found return.